package com.gitchat.controller;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.gitchat.model.User;

@RestController
@RequestMapping("/user")
public class UserController {
	
	Map<Integer, User> map = Collections.synchronizedMap(new HashMap<Integer, User>());
	
	@RequestMapping(value="/save", method=RequestMethod.POST)
	private String save(@RequestBody User user) {
		User u = new User();
		u.setId(user.getId());
		u.setName(user.getName());
		map.put(user.getId(), u);
		return "Success";
	}
	
	@RequestMapping(value="/{id}", method= RequestMethod.GET)
	private User getUser(@PathVariable Integer id) {
		User u = map.get(id);
		return u;
	}
	
}
